package com.qf.eduadmin.controller;

import com.qf.eduadmin.pojo.req.TbRolePermissionReq;
import com.qf.eduadmin.pojo.req.TbRoleReq;
import com.qf.eduadmin.pojo.resp.ResponseData;
import com.qf.eduadmin.service.TbRoleService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TbRole)表控制层
 *
 * @author makejava
 * @since 2021-12-27 20:14:02
 */
@RestController
@RequestMapping("/role")
public class TbRoleController {
    @Resource
    private TbRoleService tbRoleService;

    @RequestMapping("/findAll")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/role/findAll"})
    public ResponseData findAll(@RequestParam("page")Integer page,@RequestParam("limit")Integer limit){
        //System.out.println(page+"--"+limit);
        ResponseData responseData = tbRoleService.queryAllByLimit(page,limit);
        return responseData;
    }

    @RequestMapping("/insertRole")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/role/insertRole"})
    public ResponseData InsertRole(@RequestBody TbRoleReq tbRoleReq){
        ResponseData responseData = tbRoleService.insert(tbRoleReq);
        return responseData;
    }

    @RequestMapping("/deleteRole")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/role/deleteRole"})
    public ResponseData deleteRole(@RequestParam("id")Integer id){
        ResponseData responseData = tbRoleService.deleteById(id);
        return responseData;
    }

    @RequestMapping("/updatePermission")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/role/updatePermission"})
    public ResponseData updatePermission(@RequestBody TbRolePermissionReq tbRolePermissionReq){
        ResponseData responseData = tbRoleService.updatePermission(tbRolePermissionReq);
        return responseData;
    }

    @RequestMapping("/findRoleByUserid")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/role/findRoleByUserid"})
    public ResponseData findRoleByUserId(@RequestParam("id")Integer userId){
        ResponseData responseData = tbRoleService.findRoleByUserId(userId);
        return responseData;
    }
}